/**
 * 郭楠project
 * com.gn.micblog.util
 * LoginInterceptor.java
 * 创建人:TonyGuo 
 * 时间：2016年6月10日-下午10:57:40 
 * 2016Tm公司-版权所有
 */
package com.gn.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * LoginInterceptor
 * 创建人:TonyGuo
 * 时间：2016年6月10日-下午10:57:40 
 * @version 1.0.0
 * 
 */
public class LoginInterceptor implements HandlerInterceptor{
	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		
	}

	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {
		
	}
	/**
	 * 处理请求之前拦截
	 */
	public boolean preHandle(HttpServletRequest req, HttpServletResponse res,
			Object arg2) throws Exception {
		String loginInfo=(String)req.getSession().getAttribute("oatoken_");
		if(loginInfo==null){
			res.sendRedirect(req.getContextPath()+"/user/login.htm");
			return false;
		}
		if(!"login_ok".equals(loginInfo)){
			res.sendRedirect(req.getContextPath()+"/user/login.htm");
			return false;
		}else{
			return true;
		}
	}

}
